/**
 * Created by zhushoude on 2017/5/18.
 */
var username=localStorage.getItem("username");
var token=localStorage.getItem("token");
var userid=localStorage.getItem("userid");
$(function(){
    var src = tl_config.his_url;
    var i = src.indexOf('?');

    $("#backList").click(function(){
        var url="demand/demandSupplyList.do?ran="+Math.random();
        tl_config.loadToWorkArea(url);
    });
if(i!=-1){
    var id = src.substring(i+4);
    $.ajax({
        type : 'GET',
        contentType : 'application/json',
        async : false,
        data : {
            id : id,
            token:token
        },
        url : server_url+'/rest/demand/getDemandSupply.do?ran='+Math.random(),
        dataType : 'json',
        success : function(data) {
            if (data.retCode == "0000") {
                pasteData(data.data);
            } else{
                easyDialog.open({
                    container:{
                        header:'温馨提示',
                        content:data.retMsg
                    },
                    autoClose : 2000
                });
            }
        }
    });
}
    $("input[type=file]").change(function(){
        ajaxfileuploadUtil(this,"demandSupply");
    });

    $("#save").click(function(){
        if(!$("form").valid()){
            return;
        }
        $.ajax({
            type:'post',
            url:server_url+'/rest/demand/modifyDemandSupply.do?token='+token+'&ran='+Math.random(),
            data:$("form").serialize(),
            success:function(data){
                easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
                back();
            }
        });
    });



});

function isEmpty(data){
    if(data==null||data==undefined||data.length==0){
        return true;
    }else{
        return false;
    }
}
function pasteData(data){
    var demandSupply=data.demandSupply.data;

    $("#id").val(demandSupply.id);
    $("#usersName").text(demandSupply.usersName);
    $("#supplyName").text(demandSupply.supplyName);
    $("#amount").val(demandSupply.amount);
    $("#buyerTel").text(demandSupply.buyerTel);
    $("#supplyTel").text(demandSupply.supplyTel);
    $("[name=imgUrl1]").val(demandSupply.imgUrl1);
    $("#imgUrl1").attr("src",demandSupply.imgUrl1);
    $("[name=imgUrl2]").val(demandSupply.imgUrl2);
    $("#imgUrl2").attr("src",demandSupply.imgUrl2);
    $("[name=imgUrl3]").val(demandSupply.imgUrl3);
    $("#imgUrl3").attr("src",demandSupply.imgUrl3);

    $("#price").val(demandSupply.price);
    $("#area").val(demandSupply.area);
    $("#productName").val(demandSupply.productName);
    $("#remark").text(demandSupply.remark);

};
function back(){
    var url="demand/demandSupplyList.do?ran="+Math.random();
    tl_config.loadToWorkArea(url);
}


//刷新当前页面
var reloadFn = function(){
    window.location.reload();
};
